package com.example.thymeleaf.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.thymeleaf.pojo.DevUser;
import com.example.thymeleaf.service.DevUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;


/**
 * @Description: TODO
 * @author: 李展鹏
 * @date: 2024年05月30日20:39
 */
@Controller
@RequestMapping("/dev")
public class DevController {
    @Resource
    private DevUserService devUserService;
    @RequestMapping("/toLogin/{id}")
    public String doLogin(@PathVariable("id") Long id, Model model){
        DevUser devUser=devUserService.getOne(new QueryWrapper<DevUser>().eq("id",id));
        model.addAttribute("devUser",devUser);
        return "deom/hello";
    }
    @GetMapping(value = "/string")
    public String getString(Model model,HttpServletRequest request){
        model.addAttribute("userName","ktjiaoyv");
        request.setAttribute("test","request");
        request.getSession().setAttribute("test","session");
        model.addAttribute("date",new Date());
        return "deom/string";
    }
    @GetMapping(value = "/if")
    public String ifunless(Model model){
        model.addAttribute("flag","yes");
        model.addAttribute("sex","*");
        return "deom/if";
    }
    @GetMapping(value = "/list")
    public String list(Model model){
        List<DevUser> list =devUserService.list();
        model.addAttribute("userList",list);
        return "deom/list";
    }
    @GetMapping(value = "/index")
    public String index(){
        return "deom/index";
    }

    @GetMapping(value = "/fragment")
    public String layount(){
        return "deom/fragment";
    }


    @GetMapping(value = "/test")
    public String main(){
        return "deom/test";
    }
}
